06. Standard Library

Standard Library

"The C++ Standard Library is a collection of classes and functions, which are written in the core language and part of the C++ ISO Standard itself." Wikipedia

Learning how to use the Standard Library is an important part of becoming a proficient C++ software engineer. In almost all cases, it is preferable to utilize functionality that already exists in the Standard Library, instead of implementing functionality from scratch. This is both because using the Standard Library is faster (it is well-documented) and because many expert software engineers have worked on the Standard Library. The performance of Standard Library facilities is optimized, robust, and almost always as fast or faster than an initial re-implementation of the same functionality.

In fact, guideline SL.1 of the C++ Core Guidelines is:

Use libraries wherever possible

Reason Save time. Don’t re-invent the wheel. Don’t replicate the work of others. Benefit from other people’s work when they make improvements. Help other people when you make improvements.

And guideline SL.2 is:

Prefer the standard library to other libraries

Reason More people know the standard library. It is more likely to be stable, well-maintained, and widely available than your own code or most other libraries.

We use Standard Library features throughout the program, since proficiency with the Standard Library is a critical for C++ developers.

Namespace

Standard Library functions and classes exist in the std:: namespace. std::vector, for example, refers to the vector class within the Standard Library. Typically, in order to use a Standard Library feature we must both include the necessary header file (e.g. #include <vector>) and also namespace the class with std:: (e.g. std::vector).